﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhotoMgr.src.database;
using popLib;

namespace PhotoMgr.src.gui.photo
{
    public partial class ContestResultForm : Form
    {
        ImageList imagePic;
        List<View_RoundImage> images;
        Contest contest;

        public ContestResultForm(int contestID)
        {
            InitializeComponent();

            this.Icon = PhotoMgr.Properties.Resources.logo32;

            imagePic = new ImageList();
            imagePic.ImageSize = new Size(100, 100);
            listView1.LargeImageList = imagePic;
            listView1.View = View.LargeIcon;

            contest = DBManager.Detail_Contest(contestID);
            lbl_title.Text = contest.ContestName;

            images = DBManager.Contest_ViewResult(contestID);
            FormLib.showAnimatedLoading(this, "Hình ảnh đang được nạp.\r\nXin vui lòng đợi trong giây lát", false);
            listView1.Items.Clear();
            imagePic.Images.Clear();

            int index = 0;
            foreach (var item in images)
            {
                imagePic.Images.Add(System.Drawing.Image.FromFile(item.ImagePath));
                ListViewItem temp = new ListViewItem(item.ImageTitle + " ("+item.Score+" điểm)", index++);
                this.listView1.Items.Add(temp);
            }

            GC.Collect();
            FormLib.hideLoading(this);

        }
              

        private void listView1_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0) return;

            View_RoundImage currentImage = images[listView1.SelectedItems[0].ImageIndex];

            pbx_image.Image = System.Drawing.Image.FromFile(currentImage.ImagePath);
            pbx_image.SizeMode = PictureBoxSizeMode.Zoom;


            lbl_imageTitle.Text = currentImage.ImageTitle;
            lbl_artistName.Text = "Tác giả: " + currentImage.ArtistName;
            lbl_note.Text = currentImage.Score + " Điểm";

            GC.Collect();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
